package gui;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class IOManager {
	public static String readFileAsString(String filePath) {
		final StringBuilder builder = new StringBuilder();

		try {
			BufferedReader br = new BufferedReader(new FileReader(filePath));
			char[] buffer = new char[1024];
			int readNum;

			while ((readNum = br.read(buffer)) != -1) {
				builder.append(new String(buffer, 0, readNum));
				buffer = new char[1024];
			}

			br.close();
		} catch (IOException ex) {
		}

		return builder.toString();
	}
	
	public static List<String> readFileAsLines(String filePath) {
		final List<String> result = new ArrayList<String>();

		try {
			BufferedReader br = new BufferedReader(new FileReader(filePath));
			String line;
			
			while ((line = br.readLine()) != null) {
				result.add(line);
			}

			br.close();
		} catch (IOException ex) {
		}

		return result;
	}

	public static void saveFile(String filename, String data) {
		File outputFile = new File(filename);
		
		try {
			FileOutputStream out = new FileOutputStream(outputFile);
			out.write(data.getBytes());
			out.close();
		} catch (IOException ex) {
		}
	}
}
